//
//  HomeProjectTableViewCell.m
//  BigToBig
//
//  Created by liuyi on 7/14/16.
//  Copyright © 2016 cn.cloudtp. All rights reserved.
//

#import "HomeProjectTableViewCell.h"
#import "HomeProjectMarkCell.h"

@interface HomeProjectTableViewCell ()
<
    UICollectionViewDelegate,
    UICollectionViewDataSource
>



@end

@implementation HomeProjectTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubviews];
    }
    
    return self;
}

#pragma mark - 创建cell
- (void)createSubviews{
    
    self.markArray = [NSArray new];
    
//  头像
    self.headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, (kScreenWidth - 20)/6, (kScreenWidth - 20)/6)];
    self.headImageView.image = [UIImage imageNamed:@"touxiang"];
    [self addSubview:self.headImageView];
    self.headImageView.layer.cornerRadius = (kScreenWidth - 20)/12;
    self.headImageView.layer.masksToBounds = YES;
    
// 分类名
    UILabel *groupLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.headImageView.x, self.headImageView.maxY + 5, self.headImageView.width, self.headImageView.height / 3)];
    groupLabel.backgroundColor = COLOR_RGBA(0, 228, 161, 1);
    groupLabel.text = @"路演项目";
    groupLabel.font = [UIFont systemFontOfSize:12];
    groupLabel.textAlignment = 1;
    groupLabel.textColor = [UIColor whiteColor];
    groupLabel.layer.cornerRadius = 5;
    groupLabel.layer.masksToBounds = YES;
    [self addSubview:groupLabel];
    
// 标题
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.headImageView.maxX + 10, self.headImageView.y, kScreenWidth - self.headImageView.maxX - 10, self.headImageView.height /3)];
    self.titleLabel.text = @"创业生态园";
    [self addSubview:self.titleLabel];
    self.titleLabel.textAlignment = NSTextAlignmentLeft;
    
// 描述
    self.describeLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.titleLabel.x, self.titleLabel.maxY , self.titleLabel.width, self.titleLabel.height)];
    self.describeLabel.text = @"纯天然的无污染的。";
    [self addSubview:self.describeLabel];
    self.describeLabel.font = [UIFont systemFontOfSize:12];
    self.describeLabel.textColor = [UIColor lightGrayColor];
    
// 标签
    UICollectionViewFlowLayout *markLayout = [[UICollectionViewFlowLayout alloc]init];
    markLayout.itemSize = CGSizeMake(self.titleLabel.width / 5 , self.titleLabel.height);
    markLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    markLayout.sectionInset = UIEdgeInsetsMake(0, 5, 0, 5);
    self.markCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(self.describeLabel.x, self.describeLabel.maxY + 5, self.titleLabel.width, self.titleLabel.height) collectionViewLayout:markLayout];
    self.markCollectionView.delegate = self;
    self.markCollectionView.dataSource = self;
    self.markCollectionView.backgroundColor = [UIColor whiteColor];
    [self.markCollectionView registerClass:[HomeProjectMarkCell class] forCellWithReuseIdentifier:NSStringFromClass([HomeProjectMarkCell class])];
    [self addSubview:self.markCollectionView];
    
// 路演时间
    self.timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.markCollectionView.x, self.markCollectionView.maxY + 5, self.titleLabel.width, self.titleLabel.height)];
    self.timeLabel.text = @"路演时间:2016-06-29 11:30:00";
    self.timeLabel.font = [UIFont systemFontOfSize:14];
    self.timeLabel.textColor = [UIColor lightGrayColor];
    [self addSubview:self.timeLabel];
    
// 分割线
    UILabel *lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.timeLabel.maxY + 10, kScreenWidth, 1)];
    lineLabel.backgroundColor = COLOR_RGBA(247, 247, 247, 1);
    [self addSubview:lineLabel];
    
    
// 路演状态
    UILabel *statusTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(kScreenWidth /9 * 5, lineLabel.maxY + 10, kScreenWidth / 9 * 2, self.timeLabel.height)];
    statusTitleLabel.text = @"路演状况:";
    statusTitleLabel.font = [UIFont systemFontOfSize:statusTitleLabel.width / 5];
    [self addSubview:statusTitleLabel];
    
    self.statusLabel = [[UILabel alloc]initWithFrame:CGRectMake(statusTitleLabel.maxX, statusTitleLabel.y, kScreenWidth / 9 * 2, statusTitleLabel.height)];
    self.statusLabel.textColor = [UIColor redColor];
    self.statusLabel.font = [UIFont systemFontOfSize:statusTitleLabel.width / 5];

    self.statusLabel.text = @"已结束";
    
    [self addSubview:self.statusLabel];
    
// 已关注图标
    UIImageView *focusImageView = [[UIImageView alloc]initWithFrame:CGRectMake(statusTitleLabel.x, self.titleLabel.y, self.headImageView.width / 7 * 2, self.headImageView.width / 7 * 2)];
    focusImageView.image = [UIImage imageNamed:@"xmguanzhu"];
    [self addSubview:focusImageView];
    
// 已关注人数
    self.focusLabel = [[UILabel alloc]initWithFrame:CGRectMake(focusImageView.maxX, focusImageView.y, statusTitleLabel.width - focusImageView.width, focusImageView.height)];
    self.focusLabel.text = [NSString stringWithFormat:@"  已关注 : 2"];
    self.focusLabel.font = [UIFont systemFontOfSize:10];
    self.focusLabel.textColor = [UIColor lightGrayColor];
    [self addSubview:self.focusLabel];

// 已查看图标
    UIImageView *checkImageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.statusLabel.x, self.titleLabel.y, focusImageView.width + 5, focusImageView.height)];
    checkImageView.image = [UIImage imageNamed:@"chakan.png"];
    [self addSubview:checkImageView];

// 已查看人数
    self.checkLabel = [[UILabel alloc]initWithFrame:CGRectMake(checkImageView.maxX, checkImageView.y, self.focusLabel.width , self.focusLabel.height)];
    self.checkLabel.text = [NSString stringWithFormat:@"  已查看 : 3"];
    self.checkLabel.font = [UIFont systemFontOfSize:10];
    self.checkLabel.textColor = [UIColor lightGrayColor];
    [self addSubview:self.checkLabel];
    
    
// 底层分割线
    UILabel *bottomLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.statusLabel.maxY + 10, kScreenWidth, 150 - self.statusLabel.maxY)];
    bottomLabel.backgroundColor = COLOR_RGBA(247, 247, 247, 1);
    [self addSubview:bottomLabel];

}
- (void)setMarkArray:(NSArray *)markArray{
    _markArray = markArray;
    [self.markCollectionView reloadData];
}


#pragma mark - markCollectionView 代理方法

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.markArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    HomeProjectMarkCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([HomeProjectMarkCell class]) forIndexPath:indexPath];
    cell.markContent = self.markArray[indexPath.row];
    
    return cell;
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
